package com.vn.toaa.tintinscreenoff;

import com.startapp.android.publish.StartAppAd;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;

public class NetworkReceiver extends BroadcastReceiver {

	public static final String TAG = NetworkReceiver.class.getSimpleName();
	private Handler mHandler = new Handler();
	private StartAppAd mStartAppAd;

	@Override
	public void onReceive(Context context, Intent intent) {
		LogManager.debug(TAG, "onReceive");
		StartAppAd.init(context.getApplicationContext(), Constant.STARTAPP_DEVELOPER_ID, Constant.STARTAPP_APP_ID);
		if (mStartAppAd == null) {
			mStartAppAd = new StartAppAd(context.getApplicationContext());
		}
		mStartAppAd.onResume();

		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
		if (activeNetInfo != null) {
			if (activeNetInfo.isConnected()) {
				mHandler.post(new Runnable() {
					public void run() {
						LogManager.debug(TAG, "activeNetInfo");
						mStartAppAd.onBackPressed();
					}
				});
			}
		}
	}
}
